package com.future.dao;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

import com.future.model.po.ShareTotleModel;

public class ShareTotleDAO extends BaseDAO<ShareTotleModel> {

	public ShareTotleDAO() {

	}

	public ShareTotleDAO(Connection conn) {
		super(conn);
	}

	public boolean save(ShareTotleModel model) {
		String sql = "insert into share_totle (userid , inforid , totle ) values (?,?,?)";
		return this.update(sql, model.getUserId(), model.getInforid(), model.getTotle());
	}

	public boolean modify(ShareTotleModel model) {
		String sql = "update share_totle set inforid = ? , totle = ? where id = ? ";
		return this.update(sql, model.getInforid(), model.getTotle(), model.getId());
	}
	public boolean update(ShareTotleModel model) {
		String sql = "update share_totle set totle = ? where id = ? ";
		return this.update(sql, model.getTotle(), model.getId());
	}

	public List<ShareTotleModel> findByUserId(Integer userId) {
		ShareTotleModel model = new ShareTotleModel();
		model.setUserId(userId);
		return this.findByUserId(model);
	}

	public List<Map<String, Object>> countByUserId(Integer userId) {
		ShareTotleModel model = new ShareTotleModel();
		model.setUserId(userId);
		return countByUserId(model);
	}

	public List<Map<String, Object>> countByUserId(ShareTotleModel model) {
		String sql = "select st.id inforid , sd.department department , sd.id deptid , i.information information , st.userid userid , st.totle totle from share_totle st join information i on st.inforid = i.id join sharedepartment sd on sd.id = i.deptid where userid = ? ";
		return this.searchAsMapList(sql, model.getUserId());
	}

	public List<ShareTotleModel> findByUserId(ShareTotleModel model) {
		String sql = "select * from share_totle where userid = ? ";
		return this.searchAsBeanList(sql, ShareTotleModel.class, model.getUserId());
	}

	public boolean deleteByUserId(Integer userId) {
		ShareTotleModel model = new ShareTotleModel();
		model.setUserId(userId);
		return deleteByUserId(model);
	}

	public boolean deleteByUserId(ShareTotleModel model) {
		String sql = "delete from share_totle where userid = ? ";
		return this.update(sql, model.getUserId());
	}

}
